package com.hqyj.dao;

import com.hqyj.pojo.TbCommunity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 小区表 Mapper 接口
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@Repository
public interface TbCommunityMapper extends BaseMapper<TbCommunity> {

    @Select("select * from tb_community")
    @Results(id = "communityResults", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "buildings", javaType = List.class,
            many = @Many(select = "com.hqyj.dao.TbBuildingMapper.getBuildingsByCommunityId"))
    })
    List<TbCommunity> getCommunityWithBuild();

    @Select("select name from tb_community where id=#{id}")
    String getNameById(Integer id);

    @Select("select * from tb_community")
    List<TbCommunity> getCommunities();
}
